<template>
  <view
    class="content"
    :style="{
      'padding-top': height + 'px',
    }"
  >
    <view
      :style="{
        height: statusBarHeight + 'px',
      }"
    >
    </view>
    <view
      class="head"
      :style="{
        top: statusBarHeight + 'px',
      }"
    >
      <view class="head_left">
        <u-icon
          name="arrow-left"
          color="#FFFFFF"
          size="24"
          :bold="true"
          @click="toBack"
        ></u-icon>
      </view>
      <view class="text">收藏</view>
    </view>
    <view class="tabs_box">
      <u-tabs
        class="tabs"
        :list="list1"
        @click="tabClick"
        :activeStyle="{
          color: '#eee',
          fontWeight: 'bold',
          transform: 'scale(1.05)',
          'font-size': '34rpx',
        }"
        lineColor="#eee"
        :inactiveStyle="{
          color: '#ADADAD',
          transform: 'scale(1)',
          'font-size': '34rpx',
        }"
        :scrollable="false"
        lineWidth="72rpx"
        lineHeight="4rpx"
      ></u-tabs>
    </view>
    <scroll-view
      :style="{
        height: scrollHeihgt + 'px',
      }"
      :scroll-y="true"
      @scroll="scroll"
      @scrolltolower="scrolltolower"
    >
      <template>
        <view class="coupon_box" v-if="current == 0">
          <aoyiHall :isWhite="true" :list="kechengDetail.data"></aoyiHall>
        </view>
        <!-- 微创 -->
        <view v-show="current == 1" class="list_item">
          <view class="chooseIndex">
            <!-- <view
				    class="chooseIndex"
				    :style="{
				      background: isHeadBack ? 'rgba(0,0,0,0.3)' : 'rgba(0,0,0,0)',
				    }"
				  > -->
            <u-tabs
              :list="list4"
              lineWidth="0"
              lineColor="#f56c6c"
              :activeStyle="{
                color: '#EEEEEE',
                width: '144rpx',
                height: '56rpx',
                'line-height': '56rpx',
                'text-align': 'center',
                background: 'rgba(39,39,39,0.5)',
                'border-radius': '32rpx 32rpx 32rpx 32rpx',
                'font-size': '28rpx',
              }"
              :inactiveStyle="{
                width: '144rpx',
                height: '56rpx',
                'line-height': '56rpx',
                'text-align': 'center',
                background: 'rgba(39,39,39,0.5)',
                'border-radius': '32rpx 32rpx 32rpx 32rpx',
                color: '#ADADAD',
                'font-size': '28rpx',
              }"
              itemStyle="padding:0 20rpx; height: 56rpx'width: 144rpx"
              @change="change4"
            >
            </u-tabs>
          </view>
          <!-- 飞离洞 -->
          <view v-show="currentIndex == 0">
            <commentBlock
              :list="feiDetail.data"
              :my_level_id="my_level_id"
            ></commentBlock
          ></view>
          <!-- 灵感塔 -->
          <view v-show="currentIndex == 1">
            <!-- <lingDongT></lingDongT> -->
            <lingDD :list="lingDetail.data" :my_level_id="my_level_id"></lingDD>
          </view>
          <!-- 诗心园 -->
          <view v-show="currentIndex == 2">
            <poem
              :isShow="false"
              :showName="true"
              :list="shiDetail.data"
              :my_level_id="my_level_id"
            ></poem>
          </view>
          <!-- 文心岛 -->
          <view v-show="currentIndex == 3">
            <wenIsland
              :isShow="false"
              :currentIndex="2"
              :familyList="wenXinDetail"
              :my_level_id="my_level_id"
            ></wenIsland>
          </view>
          <!-- 游记 -->
          <view v-show="currentIndex == 4">
            <travels
              :flag="true"
              :list="youDetail"
              :showZanPing="false"
              :my_level_id="my_level_id"
            ></travels>
          </view>
          <view></view>
        </view>

        <view class="coupon_box" v-if="current == 2">
          <view
            class="box_item"
            v-for="(item, index) in bookDetail.data"
            :key="index"
            @click="toDetail(item)"
          >
            <view class="item_left" v-if="item.img.external_url">
              <image :src="item.img.external_url" mode=""></image>
            </view>
            <view class="item_right">
              <view class="right_title"> {{ item.name }} </view>
              <view class="right_author"> 关联课程：{{ item.abstract }} </view>
              <view class="right_text">
                {{ item.introduce }}
              </view>
            </view>
          </view>

          <view
            class="empty_view"
            v-if="bookDetail.data && bookDetail.data.length == 0"
          >
            <image
              class="item_left_clickable"
              src="../../static/images/my/kong.png"
              mode=""
            ></image>
            <view>当前没有相关数据，请查看其他分类或功能。</view>
          </view>
        </view>

        <view class="coupon_box" v-if="current == 3">
          <wendaoshan :list="wenDetail.data"></wendaoshan>
          <view
            class="empty_view"
            v-if="wenDetail.data && wenDetail.data.length == 0"
          >
            <image
              class="item_left_clickable"
              src="../../static/images/my/kong.png"
              mode=""
            ></image>
            <view>当前没有相关数据，请查看其他分类或功能。</view>
          </view>
        </view>

        <view class="coupon_box" v-if="current == 4">
          <peopleList
            :bgColor="'rgba(39,39,39,0.5)'"
            :color="'#eee'"
            :backBg="true"
            :list="renDetail"
          ></peopleList>
        </view>
      </template>
    </scroll-view>

    <floatingBall></floatingBall>
  </view>
</template>

<script>
import discuss from "@/components/discuss.vue";
import aoyiHall from "@/pages/stargate/components/aoyiHall.vue";
import commentBlock from "@/components/commentBlock.vue"; //飞离洞
import lingDD from "@/components/lingDD.vue"; //灵感塔
import poem from "@/components/poem.vue"; //诗心园
import wenIsland from "@/components/wenIsland.vue"; //文心岛
import starList from "@/components/starList.vue"; //星云共创
import wendaoshan from "./components/wendaoshan.vue"; //问道山
import peopleList from "@/pages/character/components/peopleList.vue"; //人物
import travels from "@/components/travels.vue"; //游记
export default {
  components: {
    discuss,
    aoyiHall,
    commentBlock,
    lingDD,
    poem,
    wenIsland,
    starList,
    wendaoshan,
    peopleList,
    travels,
  },
  data() {
    return {
      statusBarHeight: 0,
      height: 0,

      list1: [
        {
          name: "课程",
        },
        {
          name: "微创",
        },
        {
          name: "图书",
        },
        {
          name: "问道山",
        },
        {
          name: "人物",
        },
      ],
      list4: [
        {
          name: "飞离洞",
        },
        {
          name: "灵感塔",
        },
        {
          name: "诗心园",
        },
        {
          name: "文心岛",
        },
        {
          name: "游记",
        },
      ],
      scrollHeihgt: 0,
      current: 0,
      currentIndex: 0,
      itemList: [{}, {}],
      kechengDetail: {},
      feiDetail: {},
      lingDetail: {},
      shiDetail: {},
      wenXinDetail: {},
      youDetail: {},
      bookDetail: {},
      wenDetail: {},
      renDetail: {},
      page: 1,
      last_page: 0,
      my_level_id:0
    };
  },
  created() {
    const statusBarHeight = uni.getSystemInfoSync(); // 获取手机状态栏高度
    const windowHeihgt = statusBarHeight.windowHeight;
    this.statusBarHeight = statusBarHeight.statusBarHeight;
    this.$nextTick(() => {
      uni
        .createSelectorQuery()
        .select(".head")
        .boundingClientRect((data) => {
          this.height = data.height;
        })
        .exec();
    });

    this.$nextTick(() => {
      const query = uni.createSelectorQuery().in(this);
      query.select(".head").fields({
        size: true,
      });
      query.select(".tabs_box").fields({
        size: true,
      });

      query.exec((data) => {
        let sum = 0;
        data.forEach((item) => {
          sum += item.height;
        });
        this.scrollHeihgt = windowHeihgt - sum - this.statusBarHeight;
      });
    });

    // this.getShowCang();
    this.getKecheng();
  },
  onLoad() {},
  methods: {
    scrolltolower() {
      if (this.page == this.last_page || this.last_page == 0) {
      } else {
        this.page++;
        // this.getList();
        if (this.current == 0) {
          this.getKecheng();
        } else if (this.current == 1) {
          if (this.currentIndex == 0) {
            this.getFei();
          } else if (this.currentIndex == 1) {
            this.getLing();
          } else if (this.currentIndex == 2) {
            this.getShi();
          } else if (this.currentIndex == 3) {
            this.getWen();
          } else if (this.currentIndex == 4) {
            this.getYou();
          }
        } else if (this.current == 2) {
          this.getTushu();
        } else if (this.current == 3) {
          this.getWendaoshan();
        } else if (this.current == 4) {
          this.getRenwu();
        }
      }
      console.log("触发");
    },
    scroll() {},
    toDetail(item) {
      uni.navigateTo({
        url: `/pages/book/detail?id=${item.id}`,
      });
    },
    tabClick(e) {
      this.page = 1;
      this.last_page = 0;
      this.current = e.index;
      if (e.index == 0) {
        this.getKecheng();
      } else if (e.index == 1) {
        this.getFei();
      } else if (e.index == 2) {
        this.getTushu();
      } else if (e.index == 3) {
        this.getWendaoshan();
      } else if (e.index == 4) {
        this.getRenwu();
      }
    },
    change4(e) {
      this.page = 1;
      this.last_page = 0;
      this.currentIndex = e.index;
      if (e.index == 0) {
        this.getFei();
      } else if (e.index == 1) {
        this.getLing();
      } else if (e.index == 2) {
        this.getShi();
      } else if (e.index == 3) {
        this.getWen();
      } else if (e.index == 4) {
        this.getYou();
      }
    },
    toBack() {
      uni.navigateBack({
        delta: 1,
      });
    },
    getKecheng() {
      // 课程
      this.$http
        .usergongnengShouCang({ type: 1, page: this.page })
        .then((res) => {
          console.log(res.data.list, "课程");
          // this.kechengDetail = res.data.list;
          if (res.data.list.current_page == 1) {
            this.kechengDetail = res.data.list;
          } else {
            this.kechengDetail.data = this.kechengDetail.data.concat(
              res.data.list.data
            );
          }
          this.last_page = res.data.list.last_page;
        })
        .catch((error) => {
          console.log(error, "错误");
          uni.$u.toast(error);
        });
    },
    getFei() {
      // 微创-飞离洞
      this.$http
        .usergongnengShouCang({ type: 2, wei_type: 1, page: this.page })
        .then((res) => {
          console.log(res.data.list, "微创-飞离洞");
          // this.feiDetail = res.data.list;
          this.my_level_id = res.data.my_level_id
          if (res.data.list.current_page == 1) {
            this.feiDetail = res.data.list;
          } else {
            this.feiDetail.data = this.feiDetail.data.concat(
              res.data.list.data
            );
          }
          this.last_page = res.data.list.last_page;
        })
        .catch((error) => {
          console.log(error, "错误");
          uni.$u.toast(error);
        });
    },
    getLing() {
      // 微创-灵感塔
      this.$http
        .usergongnengShouCang({ type: 2, wei_type: 2,page:this.page })
        .then((res) => {
          console.log(res.data.list, "微创-灵感塔");
          // this.lingDetail = res.data.list;
          this.my_level_id = res.data.my_level_id
          if (res.data.list.current_page == 1) {
            this.lingDetail = res.data.list;
          } else {
            this.lingDetail.data = this.lingDetail.data.concat(
              res.data.list.data
            );
          }
          this.last_page = res.data.list.last_page;
        })
        .catch((error) => {
          console.log(error, "错误");
          uni.$u.toast(error);
        });
    },
    getShi() {
      // 微创-诗心园
      this.$http
        .usergongnengShouCang({ type: 2, wei_type: 3,page: this.page })
        .then((res) => {
          console.log(res.data.list, "微创-诗心园");
          // this.shiDetail = res.data.list;
          this.my_level_id = res.data.my_level_id
          if (res.data.list.current_page == 1) {
            this.shiDetail = res.data.list;
          } else {
            this.shiDetail.data = this.shiDetail.data.concat(
              res.data.list.data
            );
          }
          this.last_page = res.data.list.last_page;
        })
        .catch((error) => {
          console.log(error, "错误");
          uni.$u.toast(error);
        });
    },
    getWen() {
      // 微创-文心岛
      this.$http
        .usergongnengShouCang({ type: 2, wei_type: 4,page: this.page })
        .then((res) => {
          console.log(res.data.list, "微创-文心岛");
          // this.wenXinDetail = res.data.list;
          this.my_level_id = res.data.my_level_id
          if (res.data.list.current_page == 1) {
            this.wenXinDetail = res.data.list;
          } else {
            this.wenXinDetail.data = this.wenXinDetail.data.concat(
              res.data.list.data
            );
          }
          this.last_page = res.data.list.last_page;
        })
        .catch((error) => {
          console.log(error, "错误");
          uni.$u.toast(error);
        });
    },
    getYou() {
      // 微创-游记
      this.$http
        .usergongnengShouCang({ type: 2, wei_type: 6,page: this.page })
        .then((res) => {
          console.log(res.data.list, "微创-游记");
          // this.youDetail = res.data.list;
          this.my_level_id = res.data.my_level_id
          if (res.data.list.current_page == 1) {
            this.youDetail = res.data.list;
          } else {
            this.youDetail.data = this.youDetail.data.concat(
              res.data.list.data
            );
          }
          this.last_page = res.data.list.last_page;
        })
        .catch((error) => {
          console.log(error, "错误");
          uni.$u.toast(error);
        });
    },
    getTushu() {
      // 图书
      this.$http
        .usergongnengShouCang({ type: 3,page: this.page })
        .then((res) => {
          console.log(res.data.list, "图书");
          // this.bookDetail = res.data.list;
          if (res.data.list.current_page == 1) {
            this.bookDetail = res.data.list;
          } else {
            this.bookDetail.data = this.bookDetail.data.concat(
              res.data.list.data
            );
          }
          this.last_page = res.data.list.last_page;
        })
        .catch((error) => {
          console.log(error, "错误");
          uni.$u.toast(error);
        });
    },
    getWendaoshan() {
      // 问道山
      this.$http
        .usergongnengShouCang({ type: 4,page: this.page })
        .then((res) => {
          console.log(res.data.list, "问道山");
          // this.wenDetail = res.data.list;
          if (res.data.list.current_page == 1) {
            this.wenDetail = res.data.list;
          } else {
            this.wenDetail.data = this.wenDetail.data.concat(
              res.data.list.data
            );
          }
          this.last_page = res.data.list.last_page;
        })
        .catch((error) => {
          console.log(error, "错误");
          uni.$u.toast(error);
        });
    },
    getRenwu() {
      // 人物
      this.$http
        .usergongnengShouCang({ type: 5,page: this.page })
        .then((res) => {
          console.log(res.data.list, "人物");
          // this.renDetail = res.data.list;
          if (res.data.list.current_page == 1) {
            this.renDetail = res.data.list;
          } else {
            this.renDetail.data = this.renDetail.data.concat(
              res.data.list.data
            );
          }
          this.last_page = res.data.list.last_page;
        })
        .catch((error) => {
          console.log(error, "错误");
          uni.$u.toast(error);
        });
    },
    getShowCang() {},
  },
};
</script>

<style scoped lang="scss">
.content {
  position: fixed;
  box-sizing: border-box;
  background: url("/static/images/index.png") no-repeat;
  background-size: 100% 100%;
}

.head {
  width: 100%;
  padding: 18rpx 30rpx 47rpx;
  position: fixed;
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
  z-index: 99;

  .head_left {
    position: absolute;
    left: 30rpx;
  }

  .head_right {
    position: absolute;
    right: 30rpx;
    font-size: 30rpx;
    font-family: PingFang SC, PingFang SC;
    font-weight: 400;
    color: #55b877;
  }

  .text {
    font-size: 36rpx;
    font-family: PingFang SC-Bold, PingFang SC;
    font-weight: 400;
    color: #ffffff;
  }
}
.coupon_box {
  width: 100%;
  padding: 0 30rpx;
  padding-top: 30rpx;
  box-sizing: border-box;
  .empty_view {
    margin-top: 300rpx;
    image {
      margin: 0 auto;
      width: 410rpx;
      height: 410rpx;
    }
    view {
      font-size: 30rpx;
      color: #d8d8d8;
      text-align: center;
    }
  }
}
.list_item {
  padding-top: 30rpx;
  box-sizing: border-box;
}
.box_item {
  width: 100%;
  display: flex;
  margin-top: 32rpx;
  background: rgba(39, 39, 39, 0.5);
  border-radius: 16rpx 16rpx 16rpx 16rpx;
  padding: 32rpx;
  box-sizing: border-box;

  .item_left {
    width: 160rpx;
    height: 214rpx;

    image {
      width: 100%;
      height: 100%;
    }
  }

  .item_right {
    flex: 1;
    padding-left: 24rpx;
    box-sizing: border-box;
    position: relative;

    .right_title {
      font-size: 32rpx;
      font-family: PingFang SC-Medium, PingFang SC;
      font-weight: 400;
      color: #eeeeee;
    }

    .right_author {
      font-size: 26rpx;
      font-family: PingFang SC-Medium, PingFang SC;
      font-weight: 400;
      color: #adadad;
      overflow: hidden;
      -webkit-line-clamp: 1;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-box-orient: vertical;
    }

    .right_text {
      font-size: 26rpx;
      font-family: PingFang SC-Medium, PingFang SC;
      font-weight: 400;
      color: #eeeeee;
      position: absolute;
      bottom: 0;
      overflow: hidden;
      -webkit-line-clamp: 2;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-box-orient: vertical;
    }
  }
}
</style>